<?php

/**
 *  
 * @file   LogController.php  
 * @date   2016-10-9 18:23:24 
 * @author Zhenxun Du<5552123@qq.com>  
 * @version    SVN:$Id:$ 
 */

namespace application\admin\controller;

use think\Db;
use think\Session;

class LogController extends CommonController {

    public function index() {
        $where = array();
        $lists = db("admin_log")->where($where)->order('id desc')->paginate(10);
        $this->assign('lists', $lists);
        return $this->fetch();
    }
    public function  site(){
        $where= array();
        Session::get('user_id') != 1 ? $where['user_id'] = Session::get('user_id') : '';
      //  $where['user_id'] = '2';
        $lists = db("site")->where($where)->select();

        $this->assign('lists', $lists);
        return $this->fetch();
    }
    public function  siteInfo(){
        if(request()->isPost()){
            $file = request()->file('image_url');
            if ($file) {
                $file_types = explode(".", $_FILES ['image_url'] ['name']); // ["name"] => string(25) "excel文件名.xls"
                $file_type = $file_types [count($file_types) - 1];//xls后缀
                /*判别是不是.xls文件，判别是不是excel文件*/
                if (strtolower($file_type) != "jpg" && strtolower($file_type) != "png") {
                    echo '不是图片文件，重新上传jpg或png文件';
                    die;
                }
                $info = $file->move(ROOT_PATH . 'public' .DS.'uploads'. DS . 'images');
                if($info){
                    $path=DS.'uploads'.DS .'images/'.$info->getSaveName();
                    $map['logo'] = $path;
                }
            }
            $id = $this->request->param('id');
            if(isset($id)) {
                $map['name'] = $this->request->param('title');
                $result = Db::name('site')->where('id', $id)->update($map);
            }else{
                $map['user_id'] = Session::get('user_id');
                $map['name'] = $this->request->param('title');
                $map['addtime'] =date('Y-m-d H:i:s',time());
                $result = Db::name('site')->insert($map);
            }
            if ($result){
                $this->success('操作成功', url('site'));
            }
        }
        $id = $this->request->param('id');
        $data = Db::name('site')->where('id',$id)->find();
        $this->assign('info',$data);
        return $this->fetch();
    }

}
